package com.xianyun.book.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xianyun.book.api.ReceivedAddressServiceI;
import com.xianyun.book.dto.AddressAddCmd;
import com.xianyun.book.dto.AddressUpdateCmd;
import com.xianyun.book.dto.clientobject.ReceiveAddressCO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收货地址控制器
 * @author ytt
 */
@RestController
public class ReceivedAddressController {
    @Autowired
    private ReceivedAddressServiceI addressService;

    /**
     * 获取收货地址集合
     * @return 响应结果
     */
    @PostMapping("/received/address")
    public MultiResponse<ReceiveAddressCO> getReceiveAddressList(String securityKey){
        return addressService.getReceiveAddressList(securityKey);
    }

    /**
     * 修改收货地址
     * @return 响应结果
     */
    @PostMapping("/received/address/update")
    public Response updateReceiveAddress(AddressUpdateCmd updateCmd){
        return addressService.updateReceiveAddress(updateCmd);
    }

    /**
     * 添加收货地址
     * @return 响应结果
     */
    @PostMapping("/received/address/add")
    public Response updateReceiveAddress(AddressAddCmd addCmd){
        return addressService.addReceiveAddress(addCmd);
    }

    /**
     * 获取收货地址详情
     * @return 响应结果
     */
    @GetMapping("/received/address/{receiveId}")
    public SingleResponse<ReceiveAddressCO> getReceiveAddressInfo(@PathVariable String receiveId){
        return addressService.getAddressByReceiveId(receiveId);
    }
}
